package com.car.web.action;

import java.util.HashSet;
import java.util.Set;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import org.apache.struts2.ServletActionContext;

import com.car.util.JsonUtil;
import com.car.web.base.BaseAction;
import com.comm.cache.entity.PunishmentObj;
import com.comm.cache.entity.PunishmentSet;




/**
 * @author Administrator
 *
 */
public class PunishmentsAction extends BaseAction {

	private static final long serialVersionUID = 6855255158638463611L;
	
	public String getPunishmentsJSON() throws Throwable {
		HttpServletResponse response = ServletActionContext.getResponse(); 
		
		
		Set<PunishmentObj> punishments = new HashSet(); 
		for(int i=1;i<5;i++){
			PunishmentObj pObj = new PunishmentObj();
			pObj.setAccord("setAccord"+i);
			pObj.setClause("clause"+i);
			pObj.setContent("content"+i);
			pObj.setOrgName("orgName"+i);
			pObj.setResultDate("resultDate"+i);
			punishments.add(pObj);
		}
		
		PunishmentSet punishmentSet = new PunishmentSet();
		punishmentSet.setPunishments(punishments);
		
		//生成json的字符串
//		Punishments p = new Punishments();
//		p.setId(1);
//		p.setTestJson("testJSON");
		
		JSONArray  json = JsonUtil.getJsonArray(punishmentSet);
		
		//奖json转成json字符串
		String pjson = json.toString();
		
		//response json 的字符串
		response.setContentType("text/html;charset=utf-8"); 
		response.getWriter().write(pjson);
		response.getWriter().flush();
		return SUCCESS;
	}
	


}
